<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pr="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="/WEB-INF/facelets/admintemplate.xhtml">

        <ui:param name="title" value="Admin - View users"/>

        <ui:define name="admincontent">
            <h1>This is viewusers.xhtml</h1>

                <h:form prependId="false">
                    <pr:dataTable value="#{usersBackingBean.allUsers}" var="user">
                        <pr:column sortBy="#{user.name}">
                            <f:facet name="header">
                                <h:outputText value="User Name"/>
                            </f:facet>
                            <h:outputText value="#{user.name}"/>
                        </pr:column>

                        <pr:column sortBy="#{user.emailAddress}">
                            <f:facet name="header">
                                <h:outputText value="Email Address"/>
                            </f:facet>
                            <h:outputText value="#{user.emailAddress}"/>
                        </pr:column>


                        <pr:column sortBy="#{user.address.streetWithNumber}">
                            <f:facet name="header">
                                <h:outputText value="Street Address"/>
                            </f:facet>
                            <h:outputText value="#{user.address.streetWithNumber}"/>
                        </pr:column>

                        <pr:column sortBy="#{user.address.zipCode}">
                            <f:facet name="header">
                                <h:outputText value="Zip code"/>
                            </f:facet>
                            <h:outputText value="#{user.address.zipCode}"/>
                        </pr:column>

                        <pr:column sortBy="#{user.address.area}">
                            <f:facet name="header">
                                <h:outputText value="Area"/>
                            </f:facet>
                            <h:outputText value="#{user.address.area}"/>
                        </pr:column>

                        <pr:column sortBy="#{user.orderCount}">
                            <f:facet name="header">
                                <h:outputText value="Orders"/>
                            </f:facet>
                            <h:outputText value="#{user.orderCount}"/>
                        </pr:column>

                        <pr:column sortBy="#{user.authLevel}">
                            <f:facet name="header">
                                <h:outputText value="Authorization"/>
                            </f:facet>
                            <h:outputText value="#{user.authLevel}"/>
                        </pr:column>

                        <pr:column>
                            <f:facet name="header">
                                <h:outputText value="Edit User"/>
                            </f:facet>

                            <pr:commandButton styleClass="button" value="Invalidate" action="#{usersBackingBean.invalidate(user)}" rendered="#{user.isValid()}"/>
                            <pr:commandButton styleClass="button" value="Revalidate" action="#{usersBackingBean.revalidate(user)}" rendered="#{not user.isValid()}"/>
                            <pr:commandButton styleClass="button" value="Clear password" action="#{usersBackingBean.clearPassword(user)}"/>
                            <pr:commandButton styleClass="button" value="Make employee" action="#{usersBackingBean.setEmployee(user)}"/>
                            <pr:commandButton styleClass="button" value="Make admin" action="#{usersBackingBean.setAdmin(user)}"/>
                        </pr:column>
                    </pr:dataTable>
                </h:form>
            

        </ui:define>
    </ui:composition>
</html>

